#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/7/20 10:33
# @Author  : Sun
# @File    : read_yaml.py
# @Software: PyCharm
import yaml


class ReadYaml:

    def __init__(self):
        self.file_path = None

    def read_yaml(self, file_path=None):
        if file_path is None:
            self.file_path = r'./config/family.yaml'
        else:
            self.file_path = file_path
        with open(self.file_path, encoding='utf-8') as f:
            yaml_data = yaml.safe_load(f)
        # print(yaml_data.get(682139013))
        return yaml_data

    # Yaml写入操作
    def write_yaml(self, file_path=None, data=None):
        if file_path is None:
            self.file_path = r'./config/mis_cookies.yaml'
        else:
            self.file_path = file_path
        with open(self.file_path, mode='a', encoding='utf-8') as f:
            yaml.safe_dump(data, f)

    # Yaml清空操作
    def clear_yaml(self, file_path=None):
        if file_path is None:
            self.file_path = r'./config/family_token.yaml'
        else:
            self.file_path = file_path
        with open(self.file_path, mode='w', encoding='utf-8') as f:
            # 清空Yaml
            f.truncate()


if __name__ == '__main__':
    ReadYaml().clear_yaml('../config/family_token.yaml')
